function getReplys(text) {
  text = text.replace('素材', '');
  text = text.replace('源码', '');
  text = text.replace('程序', '');
  text = text.replace('游戏', '');
  const textLen = text.length;
  const textSet = new Set(text);
  const list = global.replys;
  let replys = [];
  for (let i = 0; i < list.length; i++) {
    let num = 0;
    let keyword = [...new Set(list[i]['keyword'])];
    for (let j = 0; j < keyword.length; j++) {
      if (textSet.has(keyword[j])) num++;
      if (num / textLen > 0.6) {
        replys.push(list[i]);
        break;
      }
    }
  }
  return replys;
}

function getArticles() {
  const commonReplys = require('./replys-common');
  const kepuReplys = require('./replys-kepu');
  const logicReplys = require('./replys-logic');
  const techReplys = require('./replys-tech');
  const scratchFestivalReplys = require('./replys-scratch-festival');
  const scratchGameReplys = require('./replys-scratch-game');
  const scratchMathReplys = require('./replys-scratch-math');

  global.replys = [
    ...commonReplys,
    ...logicReplys,
    ...kepuReplys,
    ...techReplys,
    ...scratchFestivalReplys,
    ...scratchGameReplys,
    ...scratchMathReplys,
  ];
  let text = '垃圾分类素材及源码';
  let replys = getReplys(text);
  if (replys.length == 0) {
    console.log('未找到');
  } else if (replys.length == 1) {
    console.log('找到1条');
  } else {
    console.log('replys', replys);
    console.log(`找到${replys.length}条`);
  }
}

if (process.env.NODE_ENV !== 'production') getArticles();

module.exports = { getReplys };
